package com.to8to.autotask;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.to8to.autotask.rpc.CallClient;
import com.to8to.autotask.util.DBUtil;
import com.to8to.thrift.crm.autotask.AutoTaskService;

public class RunClient
{
    public static void main(String[] args) throws Exception
    {
        AutoTaskService.Iface service = CallClient.getInstance().getAutoTaskService();

        Connection connect = DBUtil.getConnection();
        PreparedStatement stat =
            connect.prepareStatement("select * from to8to_user_info where isclose = 0 and crmroleid = 1 and cityids != '' and cityids is not null");
        ResultSet result = stat.executeQuery();
        List<Integer> list = new ArrayList<Integer>();

        while (result.next())
            list.add(result.getInt("uid"));

        DBUtil.releaseSource(result, stat, connect);

        while (true)
        {

            for (Integer uid : list)
                CallClient.getInstance().getAutoTaskService().activeOnline(uid);

            service.getOnlineUser();

            service.allocateSHKF();

            service.allocateDSGW();

            TimeUnit.SECONDS.sleep(5);
        }

    }
}
